from rest_framework import serializers
class TitleValidator(object):
    """自定义验证规则"""

    def __init__(self, base):
        self.base = str(base)

    def __call__(self, value):
        if not value.startswith(self.base):
            message = "this field must start with %s" % self.base
            raise serializers.ValidationError(message)
    def set_context(self,serializer_field):
        pass